<!DOCTYPE html>
<html lang='en'>
<head>
  <meta charset='UTF-8'>
  <meta http-equiv='X-UA-Compatible' content='IE=edge'>
  <meta name='viewport' content='width=device-width, initial-scale=1.0'>
  <title>React Document</title>
</head>
<body>
  <div id='test'></div>
  <script src='../js/react.development.js'></script>
  <script src='../js/react-dom.development.js'></script>
  <script src='../js/babel.min.js'></script>
  <script type='text/babel'>
    class Login extends React.Component {
      state = {
        username: '',
        password: ''
      }
      handleSubmit = (e) => {
        const {username, password} = this
        e.preventDefault()
        console.log(username.value)
      }
      // 使用柯里化
      handleFormData = (type) => {
        console.log(type)
        return (e) => {
          this.setState({[type]: e.target.value})
        }
      }
      saveFormData = (type, value) => {
        this.setState({[type]: value})
      }
      render() {
        return (
          <form action="http://www.baidu.com" onSubmit={this.handleSubmit}>
            {/*不使用柯里化*/}
            用户名：<input onChange={(event) => {this.saveFormData('username', event.target.value)}} type="text" name="username"/>
            密码：<input onChange={this.handleFormData('password')} type="text" name="password"/>
            <button>登录</button>
          </form>
        )
      }
    }
    ReactDOM.render(<Login/>, document.getElementById('test'))
  </script>
</body>
</html>
<!--
  高阶函数：Promise, setTimeout, arr.map(), ...
  1. 如果函数接收的参数是一个函数，则函数是高阶函数
  2. 如果函数调用的返回值是一个函数，则函数是高阶函数

  函数柯里化：通过函数调用继续返回函数的方式，实现多次接收参数最后统一处理的函数编码形式
 -->